﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <div class="form-group">
            <label class="col-sm-3 control-label ">租车品牌</label>
            <div class="col-sm-8" id="car_bindid" col="car_bindid">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">租车地址<font class="red"> *</font></label>
            <div class="col-sm-8">
                <input id="car_rental_addr" col="car_rental_addr" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">还车地址</label>
            <div class="col-sm-8">
                <input id="car_return_addr" col="car_return_addr" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">租车时间</label>
            <div class="col-sm-8">
                <input id="car_rental_time" col="car_rental_time" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">还车时间</label>
            <div class="col-sm-8">
                <input id="car_return_time" col="car_return_time" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">租车人数</label>
            <div class="col-sm-8">
                <input id="car_renters_number" col="car_renters_number" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">状态</label>
            <div class="col-sm-8" id="status" col="status">

            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    $(function () {
        $("#car_bindid").ysComboBox({
            url: '@Url.Content("~/QixingManage/BrandInfo/GetListJson")',
            key: "Id",
            value: "brand_name",
            class: "form-control",
        });

        laydate.render({ elem: '#car_rental_time', type: 'datetime', format: 'yyyy-MM-dd HH:mm:ss' });
        laydate.render({ elem: '#car_return_time', type: 'datetime', format: 'yyyy-MM-dd HH:mm:ss' });

        $("#status").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(car_status_enum).EnumToDictionaryString())) });

        getForm();

        $('#form').validate({
            rules: {
                car_rental_addr: { required: true }
            }
        });
    });

    function getForm() {
        if (id > 0) {
            ys.ajax({
                url: '@Url.Content("~/QixingManage/PrebookOrder/GetFormJson")' + '?id=' + id,
                type: 'get',
                success: function (obj) {
                    if (obj.Tag == 1) {
                        $('#form').setWebControls(obj.Data);
                    }
                }
            });
        }
        else {
            var defaultData = {};
            $('#form').setWebControls(defaultData);
        }
    }

    function saveForm(index) {
        if ($('#form').validate().form()) {
            var postData = $('#form').getWebControls({ Id: id });
            ys.ajax({
                url: '@Url.Content("~/QixingManage/PrebookOrder/SaveFormJson")',
                type: 'post',
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        }
    }
</script>

